package com.sigmatrix.h5.web.controller.utils;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.sigmatrix.h5.auth.ILoginUser;
import com.sigmatrix.h5.config.LoginUser;
import com.sigmatrix.h5.exception.MessageException;
import com.sigmatrix.h5.properties.FileWebProperties;
import com.sigmatrix.h5.service.common.upload.Base64ImageUploadRequest;
import com.sigmatrix.h5.service.common.upload.UploadService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = { "上传" })
@RestController
@RequestMapping("/util/test/upload")
public class TestUploadController {

	@Autowired
	private UploadService uploadService;

	@ApiOperation("上传图片base64")
	@PostMapping(value = "/base64Image/esecode/{esecode}")
	public List<String> base64IamgeUpload(@PathVariable String esecode,
			@Valid @RequestBody Base64ImageUploadRequest imageUploadRequest) {

		try {
			return uploadService.imageConvertAndUpload(imageUploadRequest, esecode, "h5-service/image");
		} catch (Throwable e) {
			throw new MessageException("上传失败", e);
		}
	}


	@ApiOperation("上传图片文件")
	@PostMapping(value = "/file/image/esecode/{esecode}")
	public List<String> fileImageUpload(@PathVariable String esecode, @RequestParam("file") MultipartFile file) {
		return uploadService.imageFileUpload(file, esecode, "h5-service/image");
	}
}
